package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.TraIssue;
import com.ruoyi.bussiness.service.ITraIssueService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训期号Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/issue")
public class TraIssueController extends BaseController
{
    private String prefix = "bussiness/issue";

    @Autowired
    private ITraIssueService traIssueService;

    @RequiresPermissions("bussiness:issue:view")
    @GetMapping()
    public String issue()
    {
        return prefix + "/issue";
    }

    /**
     * 查询培训期号列表
     */
    @RequiresPermissions("bussiness:issue:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TraIssue traIssue)
    {
        startPage();
        List<TraIssue> list = traIssueService.selectTraIssueList(traIssue);
        return getDataTable(list);
    }

    /**
     * 导出培训期号列表
     */
    @RequiresPermissions("bussiness:issue:export")
    @Log(title = "培训期号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TraIssue traIssue)
    {
        List<TraIssue> list = traIssueService.selectTraIssueList(traIssue);
        ExcelUtil<TraIssue> util = new ExcelUtil<TraIssue>(TraIssue.class);
        return util.exportExcel(list, "培训期号数据");
    }

    /**
     * 新增培训期号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存培训期号
     */
    @RequiresPermissions("bussiness:issue:add")
    @Log(title = "培训期号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TraIssue traIssue)
    {
        return toAjax(traIssueService.insertTraIssue(traIssue));
    }

    /**
     * 修改培训期号
     */
    @RequiresPermissions("bussiness:issue:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TraIssue traIssue = traIssueService.selectTraIssueById(id);
        mmap.put("traIssue", traIssue);
        return prefix + "/edit";
    }

    /**
     * 修改保存培训期号
     */
    @RequiresPermissions("bussiness:issue:edit")
    @Log(title = "培训期号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TraIssue traIssue)
    {
        return toAjax(traIssueService.updateTraIssue(traIssue));
    }

    /**
     * 删除培训期号
     */
    @RequiresPermissions("bussiness:issue:remove")
    @Log(title = "培训期号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(traIssueService.deleteTraIssueByIds(ids));
    }
}
